package com.example.demo.study.date;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;

public class DateTest {
    public static void main(String[] args) {
        LocalDate date = LocalDate.now();
        System.out.println("当前日期：" + date); // 输出当前日期
        System.out.println("当前年份：" + date.getYear());
        System.out.println("当前月份：" + date.getMonthValue());
        System.out.println("当前日：" + date.getDayOfMonth());
        System.out.println("**************************************");
        LocalTime time = LocalTime.now();
        System.out.println("今天时间"+time);
        System.out.println("**************************************");
        LocalDateTime datatime = LocalDateTime.now();
        System.out.println("当前日期时间：" + datatime);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        System.out.println("格式化后的日期时间：" + datatime.format(formatter));

        System.out.println("**************************************");
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int week = calendar.get(Calendar.DAY_OF_WEEK)-1;
        System.out.println("当前年月日：" + year + "年" + month + "月" + day+"日"+"星期"+week);
        System.out.println("**************************************");
        StringBuffer sb = new StringBuffer();
        System.out.println(sb.length());
        sb.append("a");
        sb.append("b");
        sb.append("c");
        System.out.println(sb.length());
        System.out.println(sb.toString());
        System.out.println("**************************************");
        sb.insert(1,"dd1");
        for (int i = 0; i < sb.length(); i++) {
            char ca = sb.charAt(i);
            System.out.print(ca);

        }


    }
}
